<template>
  <header class="header">
    <h1>todos</h1>
    <input id="toggle-all" class="toggle-all" type="checkbox" v-model="check">
    <label for="toggle-all"></label>
    <input
      class="new-todo"
      placeholder="输入任务名称-回车确认"
      autofocus
      v-model="todoName"
      @keyup.enter="add"
    />
  </header>
</template>

<script>
export default {
  props:{
    checked:Boolean
  },
  data(){
    return {
      todoName:'',
    }
  },
 methods:{
  //自定义添加新任务，传给父组件任务名
  add(){
    this.$emit('add',this.todoName)
    this.todoName=''
  }
 },
 computed:{
  //check值获取父组件统计并发过来的全选值，点击全选框改变值触发自定义全选事件
  check:{
    get(){
      return this.checked
    },
    set(val){
      this.$emit('changeAll',val)
    }
  }
 }
}
</script>